package com.kara.util;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringUtil {

	private static Object lock;
	private static SpringUtil springUtil;
	private static ApplicationContext context;

	public SpringUtil(ApplicationContext context) {
		SpringUtil.context = context;
	}

	public static Object getBean(String name) {
		if (springUtil == null) {
			synchronized (lock) {
				springUtil = new SpringUtil(getApplicationContext());
			}
		}
		return SpringUtil.context.getBean(name);
	}

	private static ApplicationContext getApplicationContext() {
		return new ClassPathXmlApplicationContext("applicationContext.xml");

	}

}
